package wait.notify.five.container.size;

import java.util.ArrayList;
import java.util.List;

public class MyContainer {

	private ArrayList<Integer> container=new ArrayList<Integer>();//Q1:为什么这样定义不好add?
	
	private static int SIZE=5;
	
//	private boolean isPutAvailable=false;
	
	public synchronized List<Integer> get(){
		while(container.size()==0){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		notify();
		return container;
	}
	
	public synchronized void put(Integer tempI){
		while(container.size()>SIZE){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		container.add(tempI);
//		if(container.size()==SIZE){
		notify();
//		}
	}
	
	
	public List<Integer> getContainer() {
		return container;
	}

	public void setContainer(ArrayList<Integer> container) {
		this.container = container;
	}
	
	
	
	
	
}
